
cd $directory

clear all
set more off
set obs 1000000

set seed 55201

qui gen a1 = rnormal()*0.02 + 0.45 // KS 42.5 D SC 44.1
qui gen a2 = rnormal()*0.02 + 0.51 // PA 50.6 D
qui gen a3 = rnormal()*0.02 + 0.57 // CO 56.9 D

qui gen b1 = rnormal()*0.02 + 0.37 // SD 36.6
qui gen b2 = rnormal()*0.02 + 0.54 // Minn 53.6 D TX 52.8 R 
qui gen b3 = rnormal()*0.02 + 0.62 // NY 61.7

qui gen c1 = rnormal()*0.02 + 0.42 // 
qui gen c2 = rnormal()*0.02 + 0.54 // Minn 53.6 D TX 52.8 R 
qui gen c3 = rnormal()*0.02 + 0.57 // 
									
qui gen d0 = rnormal()*0.0254 + 0.37 // 
qui gen d1 = rnormal()*0.0254 + 0.42 // KS 42.5 D SC 44.1
qui gen d2 = rnormal()*0.0736 + 0.54 // 
qui gen d3 = rnormal()*0.0254 + 0.60 // 
qui gen d4 = rnormal()*0.0254 + 0.62 // 

//NPV outcome
qui gen a = (a1+a2+a3)/3 //map a average
qui gen b = (b1+b2+b3)/3 //map b average
qui gen c = (d1+c2+c3)/3 //map c average
qui gen d = (d0+d1+d2+d3+d4)/5 //map d average

//EC Margins
qui gen ec_a2 = abs(a2-.5)*10000 
qui gen ec_b2 = abs(b2-.5)*10000
qui gen ec_c2 = abs(c2-.5)*10000
qui gen ec_d2 = abs(d2-.5)*6000

//NPV margins
qui gen npv_a = abs(a-.5)*30000
qui gen npv_b = abs(b-.5)*30000
qui gen npv_c = abs(a-.5)*30000
qui gen npv_d = abs(b-.5)*30000

sum a b a2 b2

matrix define T=J(4, 4, .)
forvalues i=1(1)4{
	matrix T[`i', 1] = 51
}


matrix SHARES=(.,45,51,57,.\.,37,54,62,.\.,42,54,57,.\37,42,54,60,62)
matrix list SHARES

matrix SIZE = (10000\10000\10000\6000)
matrix list SIZE


local i=1
foreach var in a b c d {
	
	summ npv_`var'
	matrix T[`i', 4] = r(mean)
	summ ec_`var'2
	matrix T[`i', 3] = r(mean)
	
	local i=`i'+1
}

matrix list T
matrix TABLE1=(SIZE,SHARES,T)


matrix list TABLE1
xml_tab TABLE1, save("tables`c(dirsep)'Table1") replace
